﻿<?php
/*
 * Copyright 2007 Bjørn Tore Håvie
 * 
 * This file is part of ITSBOT.
 * 
 * ITSBOT is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ITSBOT is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ITSBOT.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * @package ITSBOT
 * @subpackage Modules
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License
 */
/**
 * Abstract module class
 *
 */
abstract class Module{
	
	/**
	 * The bot class
	 *
	 * @var bot
	 */
	protected $irc;
	
	protected $db;
	
	/**
	 * The timer
	 *
	 * @var Timer
	 */
	protected $timer;
	
	
	protected $ext;
	
	public function __construct($db = null){
		$this->irc = Bot::Get();
		$this->timer = Timer::Get();
		$this->db = $db;
	}
	
	/**
	 * Send a message to a channel or a user
	 *
	 * @param string $chan
	 * @param string $msg
	 * 
	 * @see Bot::Say()
	 */
	protected function Say($chan, $msg){
		$this->irc->Say($chan, $msg);
	}
	
	/**
	 * Join a channel
	 *
	 * @param string $chan
	 * 
	 * @see Bot::Join()
	 */
	protected function Join($chan){
		$this->irc->Join($chan);
	}
	
	/**
	 * Add a entry to the timer
	 *
	 * @param int $time
	 * @param string $func
	 * @param mixed $arg
	 * 
	 * @see Timer::Add()
	 */
	protected function AddTimer($time, $func, $arg = null){
		$this->timer->Add(array($this, $func), $time, $arg);
	}
	
	/**
	 * Register a command
	 *
	 * @param string $name
	 * @param callback $func
	 * 
	 * @see Bot::RegisterCommand()
	 */
	protected function RegisterCommand($name, $func){
		$this->irc->RegisterCommand($name, array($this, $func));
	}
	
	/**
	 * Register a hook
	 *
	 * @param string $name
	 * @param string $func
	 * 
	 * @see Bot::RegisterHook()
	 */
	protected function RegisterHook($name, $func = null){
		if($func == null) $func = $name;
		$this->irc->RegisterHook($name, array($this, $func));
	}
}
?>